package com.chen.blue.result;

import com.chen.blue.constant.HttpStatus;
import com.chen.blue.base.ResultBase;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * Created By CLT On 2023/10/25.
 */
@SuppressWarnings("all")
@Getter
@Setter
@ApiModel(value = "响应结果")
public class R<T> implements Serializable {

    private static final long serialVersionUid = 1L;

    /**
     * 响应参数
     */
    @ApiModelProperty(value = "响应状态码", example = "200", position = 0)
    private Integer code;

    @ApiModelProperty(value = "响应消息", example = "success", position = 1)
    private String msg;

    @ApiModelProperty(value = "响应数据", position = 2)
    private T data;

    public R() {

    }

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 响应成功
     */
    public static <T> R success(T data) {
        return new R(HttpStatus.SUCCESS.getCode(), HttpStatus.SUCCESS.getDesc(), data);
    }

    public static R success() {
        return new R(HttpStatus.SUCCESS.getCode(), HttpStatus.SUCCESS.getDesc());
    }

    public static R success(String msg) {
        return new R(HttpStatus.SUCCESS.getCode(), msg);
    }

    public static <T> R success(String msg, T data) {
        return new R(HttpStatus.SUCCESS.getCode(), msg, data);
    }

    public static R success(Integer code, String msg) {
        return new R(code, msg);
    }

    /**
     * 响应失败
     */
    public static R faild(Integer code, String msg) {
        return new R(code, msg);
    }

    public static R faild() {
        return new R(HttpStatus.FAILD.getCode(), HttpStatus.FAILD.getDesc());
    }

    public static R faild(String msg) {
        return new R(HttpStatus.FAILD.getCode(), msg);
    }

}
